﻿namespace Futaba.SBus.Readers
{
	/// <summary>
	/// The interface of a stream reader to supply information to the <see cref="ISbusParsingService"/>
	/// </summary>
	public interface ISbusStreamReader
	{
		/// <summary>
		/// Opens the underlying stream
		/// </summary>
		void OpenPort();
		/// <summary>
		/// Closes the underlying stream and releases all related resources
		/// </summary>
		void ReleasePort();

		/// <summary>
		/// Returns the next byte waiting in the stream's buffer, or NULL, if no data is available
		/// </summary>
		/// <returns></returns>
		byte? ReadByte();
		/// <summary>
		/// Returns the next byte waiting in the stream's buffer but will not remove it from the 
		/// buffer, or NULL, if no data is available
		/// </summary>
		/// <remarks>
		/// Multiple calls will always return the same byte value (if a non-null value has been returned
		/// on previous calls), until <see cref="ReadByte"/> has been called
		/// </remarks>
    byte? Peek();
		/// <summary>
		/// Works similar to <see cref="Peek"/>, but will consume the byte, if it matches the
		/// <paramref name="match">supplied value</paramref>
		/// </summary>
		/// <param name="match">the value to match against</param>
		/// <returns></returns>
		bool ReadIfMatch(byte match);
	}
}
